import Vue from 'vue'

import API from '../config/localApi'

function getData(api) {
  return (id = null) => 
    id === null ? Vue.http.get(api.url) :
                  Vue.http.get(api.url + id)
}

export default {
  actions: {
    getNewslist() {
      return getData( API.news_list )()
    },
    getNewsInfo({}, id) {
      return getData( API.news_info )(id)
    },
    getImgCategory() {
      return getData( API.imgcategory )()
    },
    getImages({}, id) {
      return getData( API.img_list )(id)
    },
    getImgInfo({}, id) {
      return getData( API.img_info )(id)
    },
    getGoods({}, pageNum) {
      return Vue.http.get('http://localhost:3000/api/getgoods?pageindex='+ pageNum)
    },
    getGoodsInfo({}, id) {
      return getData( API.goods_info )(id)
    },
    getGoodsDesc({}, id) {
      return getData( API.goods_desc )(id)
    },
    getShopCarList({}, ids) {
      return getData( API.shopcar_list )(ids)
    },
    getComments({}, {id, pageNum}) {
      return Vue.http.get('http://localhost:3000/api/getComments/'+ id + '?pageNum='+ pageNum)
    },
    addComment({}, {id, content}) {
      return Vue.http.post('http://localhost:3000/api/addComments/'+ id, { content })
    }
  }
}